<template>
  <div>
    <div class="app-main-content-box">
      <app-main-title title="会员码规则" />

      <div>
        <el-form ref="form" :model="form" :rules="rules" label-width="100px" size="small">
          <el-form-item>
            <el-tag>
              <i class="el-icon-warning" />
              &nbsp;配置会员小程序页面会员码的展示规则
            </el-tag>
          </el-form-item>
          <el-form-item label="码类型：" prop="codeType">
            <el-radio v-model="form.codeType" :label="1">动态码(默认)</el-radio>
            <el-radio v-model="form.codeType" :label="2">静态码(会员手机号)</el-radio>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" round @click="submit">保 存</el-button>
            <el-button round @click="fetchData">重 置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { getMemberCodeConfig, saveMemberCodeConfig } from '@/api/vip'
export default {
  data() {
    return {
      // 校验字段相关
      rules: {
        codeType: [
          { required: true, message: '请选择码类型', trigger: 'change' }
        ]
      },
      // 配置
      // 状态
      loading: false,
      // 数据
      form: {
        codeType: 1
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.fetchData()
  },
  methods: {
    /**
       * 数据组
       */
    // 获取数据
    fetchData() {
      this.loading = true
      getMemberCodeConfig()
        .then(res => {
          this.form = res.data
        })
        .catch(err => {})
        .finally(() => {
          this.loading = false
        })
    },

    /**
       * 按钮组
       */
    // 保存
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          saveMemberCodeConfig({ type: this.form.codeType })
            .then(res => {
              this.$notify({
                title: '成功',
                message: '保存成功',
                type: 'success',
                duration: 2000,
                offset: 40
              })
            })
            .catch(err => {})
            .finally(() => {
              this.loading = false
            })
        }
      })
    }

    /**
       * 状态组
       */
    /**
       * 方法组
       */
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  .el-icon-warning {
    font-size: 14px;
  }
</style>
